import { sequelize } from '../../db';
import { Model, DataTypes } from 'sequelize';
import { lostTime } from '../../../code/util';

class Rate extends Model { }

Rate.init({
    TemplateId: DataTypes.INTEGER,
    RateId: DataTypes.INTEGER,
    UserId: DataTypes.INTEGER,
    message: DataTypes.STRING,
    rate: DataTypes.INTEGER,
    create: {
        type: DataTypes.VIRTUAL,
        get() {
            return lostTime(this.dataValues.createdAt)
        },
        set(value) {
            throw new Error('不要尝试设置 `create` 的值!');
        }
    },
    readed: {
        type: DataTypes.BOOLEAN,
        defaultValue: false
    }
}, {
    sequelize
});

export default Rate